package com.example.qxfw.backgroundManagement.service.impl;

import com.example.qxfw.backgroundManagement.mapper.ProductManagerMapper;
import com.example.qxfw.backgroundManagement.service.ProductManagerService;
import com.example.qxfw.common.entity.UserProduct;
import com.example.qxfw.common.entity.UserTable;
import com.example.qxfw.rcyw.pojo.JobMake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/6/30  星期五   15:55
 * @description : 此类用来
 ***************************************/
@Service
public class ProductManagerServiceImpl implements ProductManagerService {

    @Autowired
    private ProductManagerMapper productManagerMapper;
    @Override
    public List<UserTable> selectIdAndUserName() {
        return this.productManagerMapper.selectIdAndUserName();
    }

    @Override
    public List<UserProduct> selectProductType() {
        return this.productManagerMapper.selectProductType();
    }

    @Override
    public List<JobMake> selectJobType() {
        return this.productManagerMapper.selectJobType();
    }

    @Override
    public List<UserProduct> selectUserProductByUserId(final String startTime, final String endTime, final String productType, final String productName) {
        List<Integer> idList = this.productManagerMapper.selectIds();
        List<UserProduct> userProducts = this.productManagerMapper.selectUserProductByUserId(idList, Timestamp.valueOf(startTime), Timestamp.valueOf(endTime), productType, productName);
        return userProducts;
    }

    @Override
    public Integer insertUserProduct(final UserProduct userProduct) {
        Integer idMax = this.productManagerMapper.selectIdMax();
        Integer integer = this.productManagerMapper.saveUserProduct(idMax, userProduct);
        return integer;
    }

    @Override
    public Integer updateUserProduct(final UserProduct userProduct) {
        return this.productManagerMapper.updateUserProduct(userProduct);
    }

    @Override
    public Integer deleteUserProduct(final int id) {
        return this.productManagerMapper.deleteUserProduct(id);
    }

    @Override
    public List<UserProduct> exportUserTable() {
        List<UserTable> userTables = this.productManagerMapper.selectIdAndUserName();
        List<Integer> ids = new ArrayList<>();
        userTables.forEach(userTable -> {
            ids.add(userTable.getId());
        });
        List<UserProduct> userProducts = this.productManagerMapper.exportUserProduct(ids);
        return userProducts;
    }

    @Override
    public Integer importUserProduct(final UserProduct userProduct) {
        Integer integer = this.productManagerMapper.clearUserProduct();
        Integer idMax = this.productManagerMapper.selectIdMax();
        Integer integer1 = this.productManagerMapper.saveUserProduct(idMax, userProduct);
        return integer1;
    }

    @Override
    public List<UserProduct> selectProductName(final String productType) {

        List<UserProduct> userProducts = this.productManagerMapper.selectProductName(productType);
        return userProducts;
    }

    @Override
    public List<JobMake> selectJobName(final String jobType) {
        List<JobMake> jobMakes = this.productManagerMapper.selectJobName(jobType);
        return jobMakes;
    }
}
